var http = require('http')
var querystring = require('querystring')

var postData = querystring.stringify({
	'content' : '期待下一期课程',
	'cid' : 348,
	'checked':1,
})

var option = {
	hostname : 'www.imooc.com',
	port : 80,
	path : '/course/docomment',
	method : 'POST',
	headers : {
		'Accept':'application/json, text/javascript', 
		'Accept-Encoding':'gzip, deflate',
		'Accept-Language':'zh-CN,zh;q=0.8',
		'Connection':'keep-alive',
		'Content-Length':postData.length,
		'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
		'Cookie':'PHPSESSID=33i5conmdgu1r6nvasr5mqvcl3; imooc_uuid=63647197-ee89-49a6-913b-5c2241f55cee; imooc_isnew=1; imooc_isnew_ct=1451656030; IMCDNS=0; loginstate=1; apsid=g3MmUzMjAyNWUwZWNiNjNmNGFmZGE1YWFiNWUzNDQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjU0OTE0MwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5OTYyNjA1MDZAcXEuY29tAAAAAAAAAAAAAAAAAAAAADNmMzkwZDViNDlmZWJmYjk2ZTg1YjUxNTIwZjAzMzdif4OGVn%2BDhlY%3DND; last_login_username=996260506%40qq.com; cvde=5686835ed65ed-16; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1451656038; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1451661217',
		'Host':'www.imooc.com',
		'Origin':'http://www.imooc.com',
		'Referer':'http://www.imooc.com/comment/348',
		'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36',
		'X-Requested-With':'XMLHttpRequest',
	}

}

var req = http.request(option, function(res){
	console.log('Status:'+res.statusCode)
	console.log('headers'+JSON.stringify(res.headers))

	res.on('data',function(chunk){
		console.log(Buffer.isBuffer(chunk))
		console.log(typeof chunk)
	})

	res.on('end',function(){
		console.log('评论完毕')
	})	
})

req.on('error',function(e){
	console.log('Error:'+e.message)
})

req.write(postData)

req.end()